package com.lm56.web.search;

import com.lm56.web.queryhistory.QueryHistory;
import com.lm56.web.queryhistory.QueryHistoryService;
import com.lm56.web.waybill.domain.WaybillTraceDTO;
import com.lm56.web.search.SearchMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Kelvin Yeung on 2016/11/20.
 */
@Component
@Transactional
public class SearchService {

    @Autowired
    SearchMapper searchMapper;

    @Autowired
    QueryHistoryService queryHistoryService;

    public List<WaybillTraceDTO> getWaybillTraceByPhoneNo(SearchForm searchForm){
        List<WaybillTraceDTO> waybillTraces = searchMapper.getWaybillTraceByPhoneNo(searchForm);
        if(waybillTraces!=null &&waybillTraces.size()>0){
            for (WaybillTraceDTO traces : waybillTraces){
                queryHistoryService.log(traces.getWaybillId(),traces.getWaybillNo(),traces.getComName(),QueryHistory.TYPE_LOGISTICS);
            }
        }
        return waybillTraces;
    }



    public List<WaybillTraceDTO> getWaybillTraceWaybillNoAndCompany(SearchForm searchForm){
        List<WaybillTraceDTO> waybillTraces =searchMapper.getWaybillTraceWaybillNoAndCompany(searchForm);
        if(waybillTraces!=null &&waybillTraces.size()>0){
            for (WaybillTraceDTO traces : waybillTraces){
                queryHistoryService.log(traces.getWaybillId(),traces.getWaybillNo(),traces.getComName(),QueryHistory.TYPE_LOGISTICS);
            }
        }
        return waybillTraces;
    }


}
